import * as actionType from "./constant";
import { fromJS } from "immutable";

import {
  getBannerListRequest,
  getRecommendListRequest,
} from "../../../api/request";

export const changeBannerListAction = (data) => ({
  type: actionType.CHANGE_BANNER,
  data: fromJS(data),
});

export const changeRecommendListAction = (data) => ({
  type: actionType.CHANGE_RECOMMEND_LIST,
  data: fromJS(data),
});

export const getBannerList = () => {
  return (dispatch) => {
    getBannerListRequest()
      .then((res) => {
        dispatch(changeBannerListAction(res.banners));
      })
      .catch((err) => console.log(err));
  };
};

export const getRecommendList = () => {
  return (dispatch) => {
    getRecommendListRequest()
      .then((res) => {
        dispatch(changeBannerListAction(res.result));
      })
      .catch((err) => console.log(err));
  };
};
